
capture use "data files/sen_r6_local.dta", clear


drop EA_SVC_A - strtime

gen year_survey = 2014
gen round = 6


***********************
***   Demographic   ***
***********************

decode urbrur, gen(urb)
drop urbrur
ren urb urbrur

** Age **
gen age = Q1
label var age "Age of respondent"
replace age=. if age == -1 | age==999| age==98
drop Q1

** Gender **

decode Q101, gen (gender)
label var gender "Gender of respondent"
drop Q101

** Education **

gen no_school = 0 if Q97!=-1 & Q97!=. & Q97!=99
replace no_school = 1 if Q97==0 
label var no_school "No formal schooling"
gen informal_school = 0 if Q97!=-1 & Q97!=. & Q97!=99
replace informal_school = 1 if Q97==1
label var informal_school "Informal schooling only"


gen primary_school_inc = 0 if Q97!=-1 & Q97!=. & Q97!=99
replace primary_school_inc = 1 if Q97>=2 & Q97<=9
gen primary_school = 0 if Q97!=-1 & Q97!=. & Q97!=99
replace primary_school = 1 if Q97>=3 & Q97<=9
gen secondary_school_inc = 0 if Q97!=-1 & Q97!=. & Q97!=99
replace secondary_school_inc = 1 if Q97>=4 & Q97<=9
gen secondary_school = 0 if Q97!=-1 & Q97!=. & Q97!=99
replace secondary_school = 1 if Q97>=5 & Q97<=9
gen college = 0 if Q97!=-1 & Q97!=. & Q97!=99
replace college = 1 if Q97>=7 & Q97<=9
label var college "Some college, even if incomplete"
drop Q97

** Religion **
gen religion=""
replace religion="None" if Q98A==0 | Q98A==28 | Q98A==29
replace religion="Muslim" if (Q98A>=18 & Q98A<=24) | Q98A == 660 
replace religion="Christian" if (Q98A>=1 & Q98A<=17 ) | (Q98A>=30 & Q98A<=33)
replace religion="Traditional" if Q98A==25
replace religion="Other" if Q98A==34 | Q98A== 9995
replace religion="Unknown" if Q98A==9998  | Q98A==-1 | Q98A==9999


gen ethnicity = Q87
replace ethnicity = . if Q87 >= 9990 | Q87 < 0

gen wolof = 0 if ethnicity != .
replace wolof = 1 if ethnicity == 660

gen toucpeul = 0 if ethnicity != .
replace toucpeul = 1 if ethnicity == 661

gen serer = 0 if ethnicity != .
replace serer = 1 if ethnicity == 662

gen bambara = 0 if ethnicity != .
replace bambara = 1 if ethnicity == 663

gen soninke = 0 if ethnicity != .
replace soninke = 1 if ethnicity == 664

gen diola = 0 if ethnicity != .
replace diola = 1 if ethnicity == 665

gen others = 0 if ethnicity != .
replace others = 1 if ethnicity == 668 | ethnicity == 669 | ethnicity == 666


gen language = Q2

gen french_lang = 0 if language != .
replace french_lang = 1 if language == 2

gen wolof_lang = 0 if language != .
replace wolof_lang = 1 if language == 660

gen toucpeul_lang = 0 if language != .
replace toucpeul_lang = 1 if language == 661

gen serer_lang = 0 if language != .
replace serer_lang = 1 if language == 662

gen mand_lang = 0 if language != .
replace mand_lang = 1 if language == 663 

gen diola_lang = 0 if language != .
replace diola_lang = 1 if language == 665

gen other_lang = 0 if lang != .
replace other_lang = 1 if wolof_lang == 0 & toucpeul_lang == 0 & serer_lang == 0 & mand_lang == 0 & diola_lang == 0



********************
***   Economic   ***
********************


gen no_food = 0 if Q8A!=-1 & Q8A!=. & Q8A!=9
replace no_food = 1 if Q8A==2 | Q8A==3 | Q8A==4

gen no_water = 0 if Q8B!=-1 & Q8B!=. & Q8B!=9
replace no_water = 1 if Q8B==2 | Q8B==3 | Q8B==4

gen no_healthcare = 0 if Q8C!=-1 & Q8C!=. & Q8C!=9
replace no_healthcare = 1 if Q8C==2 | Q8C==3 | Q8C==4

gen no_fuel = 0 if Q8D!=-1 & Q8D!=. & Q8D!=9
replace no_fuel = 1 if Q8D==2 | Q8D==3 | Q8D==4

gen no_income = 0 if Q8E!=-1 & Q8E!=. & Q8E!=9
replace no_income = 1 if Q8E==2 | Q8E==3 | Q8E==4


*** Employment Variables ***

gen employment_status = "" if Q95!=. & Q95!=-1 & Q95!=9
replace employment_status = "inactive" if  Q95==0
replace employment_status = "unemployed" if Q95==1
replace employment_status = "part-time" if Q95==2
replace employment_status = "full-time" if Q95==3

*** Assets *** 
gen owns_radio = 0 if Q91A!=. & Q91A!=-1 & Q91A!=9
replace owns_radio = 1 if Q91A==1

gen owns_tv = 0 if Q91B!=. & Q91B!=-1 & Q91B!=9
replace owns_tv = 1  if Q91B==1

gen owns_vehicle = 0 if Q91C!=. & Q91C!=-1 & Q91C!=9
replace owns_vehicle = 1  if Q91C==1


**************************
***   Interest index   ***
**************************

gen discuss_pol_index = Q14 if Q14 >= 0 & Q14 <= 2 

gen interest_pub_affairs_index = 0 if Q13!=-1 & Q13!=. & Q13!=9
replace interest_pub_affairs_index = 1 if Q13==2 | Q13==3
replace interest_pub_affairs_index = 2 if Q13==3

**** Information and Media ***

gen radio = Q12A if Q12A!=-1 & Q12A!=. & Q12A!=9 & Q12A != 98
gen tv = Q12A if Q12B!=-1 & Q12B!=. & Q12B!=9 & Q12B != 98
gen newspaper = Q12C if Q12C!=-1 & Q12C!=. & Q12C!=9 & Q12C != 98
gen internet = Q12D if Q12D!=-1 & Q12D!=. & Q12D!=9 & Q12D != 98

gen radio_news_often =0 if Q12A!=-1 & Q12A!=. & Q12A!=9
replace  radio_news_often =1 if Q12A==4

gen tv_news_often =0 if Q12B!=-1 & Q12B!=. & Q12B!=9
replace  tv_news_often =1 if Q12B==4

gen newspaper_news_often =0 if Q12C !=-1 & Q12C !=. & Q12C !=9
replace  newspaper_news_often =1 if Q12C ==4

gen internet_news_often =0 if Q12D !=-1 & Q12D !=. & Q12D !=9
replace  internet_news_often =1 if Q12D ==4

gen social_media_news_often =0 if Q12E !=-1 & Q12E !=. & Q12E !=9
replace  social_media_news_often =1 if Q12E ==4


*************************
***   Participation   ***
*************************

gen contact_LG_councilor_index = Q24A if Q24A!=. & Q24A!=-1 & Q24A!=9 & Q24A != 98

gen contact_MP_index = Q24B if Q24B!=. & Q24B!=-1 & Q24B!=9 & Q24B != 98

gen contact_officials_index = Q24C if Q24C!=. & Q24C!=-1 & Q24C!=9 & Q24C != 98

gen att_demonstration_index = Q27E if Q27E!=. & Q27E!=-1 & Q27E!=9 & Q27E != 98

gen raise_issue_index = Q20B  if Q20B!=. & Q20B!=-1 & Q20B!=9 & Q20B != 98

gen vote1 = 0 if Q21 !=-1 & Q21 !=9 &  Q21 !=.
replace vote1 = 1 if Q21==1

gen close_pds = 0 if Q90B <= 9997 & Q90B != . & Q90B != -1
replace close_pds = 1 if Q90B == 660


***********************************
***   Democratic institutions   ***
***********************************

gen trust_EC = Q52C if Q52C!=. & Q52C!=-1 &  Q52C!=9
gen trust_courts=Q52J if Q52J !=. & Q52J !=-1 & Q52J!=9
gen careful_say = Q51A if Q51A !=. & Q51A!= -1 & Q51A!=9 
gen elections_free_fair = Q22 if Q22 < 8 & Q22 >= 0

gen free_to_speak_mind= 0 if Q15A!=. &   Q15A!=-1
replace free_to_speak_mind= 1 if Q15A==3
replace free_to_speak_mind= 2 if Q15A==4

gen free_to_join_pol_org= 0 if Q15B!=. &   Q15B!=-1
replace free_to_join_pol_org= 1 if Q15B==3
replace free_to_join_pol_org= 2 if Q15B==4

gen free_vote_choice= 0 if Q15C!=. &   Q15C!=-1
replace free_vote_choice= 1 if Q15C==3
replace free_vote_choice= 2 if Q15C==4


gen how_democratic=0 if Q40!=.  & Q40!=9
replace how_democratic=1 if Q40==3
replace how_democratic=2 if Q40==4
label var how_democratic "Believe that Senegal is a functioning democracy"
drop Q40


gen satisfaction_democracy = 0 if Q41!=. & Q41!=9
replace satisfaction_democracy = 1 if Q41==3
replace satisfaction_democracy = 2 if Q41==4
label var satisfaction_democracy "Satisfaction democracy"
drop Q41


gen checks_balances =0 if Q34!=. &  Q34!=-1 & Q34!=9
replace checks_balances =1 if Q34==1 |  Q34==2

gen checks_balances_strong =0 if  Q34!=. &  Q34!=-1 & Q34!=9
replace checks_balances_strong =1 if Q34==1
drop Q34

gen against_govt_ban_org=0 if Q16!=-1 & Q16!=. & Q16!=9
replace against_govt_ban_org=1 if Q16==3| Q16==4

gen against_govt_ban_org_str=0 if Q16!=-1 & Q16!=. &Q16!=9
replace against_govt_ban_org_str=1 if Q16==4


gen against_president_discretion =0 if Q38!=. & Q38!=-1 &  Q38!=9
replace against_president_discretion =1 if Q38==3 |  Q38==4

gen against_pres_discr_strong =0 if Q38!=. & Q38!=-1 & Q38!=9
replace against_pres_discr_strong =1 if Q38==4
drop Q38

gen term_limits =0 if Q39!=.  & Q39!=-1  & Q39!=9 
replace term_limits  =1 if Q39 ==1 | Q39 ==2

gen term_limits_strongly =0 if Q39!=.  & Q39!=-1 & Q39!=9 
replace term_limits_strongly  =1 if Q39 ==1
drop Q39

gen media_accountability =0 if Q36!=. &  Q36!=-1 & Q36!=9
replace media_accountability =1 if Q36==1 | Q36==2

gen media_accountability_strong =0 if Q36!=. &  Q36!=-1 & Q36!=9
replace media_accountability_strong =1 if Q36==1
label var media_accountability "Believe media should check government"
drop Q36

gen opp_parties_criticize =0 if Q35!=. &  Q35!=-1 & Q35!=9
replace opp_parties_criticize =1 if Q35==1 | Q35==2

gen opp_parties_crit_str =0 if Q35!=. &  Q35!=-1 & Q35!=9
replace opp_parties_crit_str =1 if Q35==1
label var opp_parties_criticize "Believe opposition parties should examine government"
drop Q35 



gen against_one_party_rule =0 if Q28A!=. & Q28A!=-1 & Q28A!=9
replace against_one_party_rule =1 if Q28A == 1 | Q28A==2

gen a_one_party_rule_strong =0 if Q28A!=. & Q28A!=-1 & Q28A!=9
replace a_one_party_rule_strong =1 if Q28A == 1 

gen reject_military_rule =0 if Q28B!=. & Q28B!=-1 & Q28B!=9
replace reject_military_rule =1 if Q28B == 1 | Q28B==2

gen r_mil_rule_str =0 if Q28B!=. & Q28B!=-1 & Q28B!=9
replace r_mil_rule_str =1 if Q28B == 1

gen reject_one_man_rule =0 if Q28C!=. & Q28C!=-1 &  Q28C!=9
replace reject_one_man_rule =1 if Q28C == 1 | Q28C==2

gen r_one_man_r_strongly =0 if Q28C!=. & Q28C!=-1 & Q28C!=9
replace r_one_man_r_strongly =1 if Q28C == 1 
drop Q28*


gen election_choice_leaders = 0 if Q32!=.  & Q32!=-1  & Q32!=9
replace election_choice_leaders = 1 if Q32==1  | Q32==2

gen election_choice_leaders_str = 0 if Q32!=.  & Q32!=-1  & Q32!=9
replace election_choice_leaders_str = 1 if Q32==1 

gen supports_democracy=0 if Q30!=. & Q30!=-1
replace supports_democracy=1 if Q30==3
label var supports_democracy "Supports democracy"

gen newspaper_free=0 if Q17!=-1 & Q17!=. &Q17!=9
replace newspaper_free=1 if Q17==1 | Q17 ==2 

gen newspaper_free_str=0 if Q17!=-1 & Q17!=. &Q17!=9
replace newspaper_free_str=1 if Q17 == 1



*** Trust in different institutions ***

gen trust_president =Q52A if Q52A!=. & Q52A!=-1 & Q52A!=9

gen trust_national_assembly=Q52B if Q52B!=. &  Q52B!=-1 & Q52B!=9

gen trust_LG_council=Q52E if Q52E!=. & Q52E!=-1 & Q52E!=9

gen trust_ruling_party=Q52F if Q52F!=. & Q52F!=-1 & Q52F!=9

gen trust_opposition_party=Q52G if Q52G!=. & Q52G!=-1 & Q52G!=9

gen trust_traditional_leaders=Q52K if Q52K!=. & Q52K!=-1 & Q52K!=9

gen trust_religious_leaders=Q52L if Q52L!=. & Q52L!=-1 & Q52L!=9
drop Q52*


*** Government performance ***


gen present_econ = Q4A - 1 if Q4A!=. & Q4A!=-1 & Q4A!=9
label var present_econ "Economic conditions"

gen personal_econ = Q4B - 1 if Q4B!=. & Q4B!=-1 & Q4B!=9
label var personal_econ "Personal economic conditions"

gen past_econ = Q6 - 1 if Q6!=. & Q6!=-1 & Q6!=9
label var past_econ "Compare econ, past 12mths"

gen future_econ = Q7 - 1 if Q7!=. & Q7!=-1 & Q7!=9
label var future_econ "Future econ (12mth)"

gen handles_economy =Q66A-1 if Q66A!=. & Q66A!=-1 & Q66A!=9
label var handles_economy "Government handles economy"

gen handles_employment=Q66C-1 if Q66C!=. & Q66C!=-1 & Q66C!=9
label var handles_employment "Government handles employment"

gen handles_inflation=Q66D-1 if Q66D!=. & Q66D!=-1 & Q66D!=9
label var handles_inflation "Government handles inflation"

gen handles_inequality=Q66E-1 if Q66E!=. & Q66E!=-1 & Q66E!=9
label var handles_inequality "Government handles inequality"

gen handles_health=Q66G-1 if Q66G!=. & Q66G!=-1 & Q66G!=9
label var handles_health "Government handles health provision"

gen handles_education=Q66H-1 if Q66H!=. & Q66H!=-1 & Q66H!=9
label var handles_education "Government handles education provision"

gen handles_water=Q66I-1 if Q66I!=. & Q66I!=-1 & Q66I!=9
label var handles_water "Government handles water provisoon"
drop Q66*


gen loc_gov_handles_roads=Q67A-1 if Q67A!=. & Q67A!=-1 & Q67A!=9
label var loc_gov_handles_roads "Local government handles roads"

gen loc_gov_handles_markets=Q67B-1 if Q67B!=. & Q67B!=-1 & Q67B!=9
label var loc_gov_handles_markets "Local government handles markets"
drop Q67*

gen performance_president = Q68A-1 if Q68A!=. & Q68A!=-1 & Q68A!=9
label var performance_president "Approves President perfomance"
 
gen performance_mp  = Q68B-1 if Q68B!=. & Q68B!=-1 & Q68B!=9
label var performance_mp "Approves MP perfomance"

gen performance_LG_councilor  = Q68C-1 if Q68C!=. & Q68C!=-1 & Q68C!=9
label var performance_LG_councilor "Approves LG councilor perfomance"
drop Q68*

gen MP_listen = Q59A if Q59A !=. & Q59A !=-1 & Q59A !=9
label var  MP_listen "MPs listen to people's interests"

gen LG_councilor_listen = Q59B if Q59B !=. & Q59B !=-1 & Q59B !=9
label var  LG_councilor_listen "LG Counncilors listen to people's interests"
drop Q59*

gen corruption_president = Q53A if Q53A !=. &  Q53A !=-1 &  Q53A !=9
label var corruption_president "Very corrupt president office"

gen corruption_MP = Q53B if Q53B !=. &  Q53B !=-1 &  Q53B !=9
label var corruption_MP "Very corrupt MPs"

gen corruption_government_officials = Q53C if Q53C !=. &  Q53C !=-1 &  Q53C !=9 
label var corruption_government_officials "Very corrupt government officials"

gen corruption_LG_councilors = Q53D if Q53D  !=. &  Q53D  !=-1 &  Q53D  !=9
label var corruption_LG_councilors "Very corrupt LG councilors"


gen corr_pres_dk = Q53A == 9  if Q53A !=. &  Q53A !=-1
gen corr_mp_dk = Q53B == 9  if Q53B !=. &  Q53B !=-1
gen corr_lg_dk = Q53C == 9  if Q53C !=. &  Q53C !=-1
gen corr_gov_dk = Q53D == 9  if Q53D !=. &  Q53D !=-1


drop Q53*

drop eanumb-Q117




